function createElement(type, attributes, ...children) {
  var element;
  if (typeof type === "string" ) {
    element = document.createElement(type)
  } else {
    element = new type;
  }

  for (let name in attributes) {
    element.setAttribute(name, attributes[name]);
  }

  for (let child of children) {
    if (typeof child === 'string') {
      child = document.createTextNode(child)
    }
    element.appendChild(child)
  }

  return element;
}

class Div {
  constructor() {
  }
  setAttribute() {}
  appendChild() {}
  mountTo(parent) {
    this.root = document.createElement("div");
    parent.appendChild(this.root)
  }
}

// 最简单的 jsx
let a = <Div id="a">
  'Hello World'
</Div>

// document.body.appendChild(a)

a.mountTo(document.body)

/*
* 浏览器运行
* Sources 里面找
*
var a = createElement("div",
  {id: "a"},
  createElement("span", null),
  createElement("span", null),
  createElement("span", null)
);
*/

/**
 *
 * error without handle TextNode
 *
 *
 * var a = createElement("div", {
  id: "a"
}, "'Hello World'");
 document.body.appendChild(a);
 *
 *
 * */
